import React from 'react'
import { useReducer } from 'react';
function reducer (state, action){
  switch(action.type){
    case 'INCREMENT':
      return {count: state.count + 1};
    case 'DECREMENT':
      return {count: state.count - 1};
    case 'UPDATE':
      return {count: action.payload};
    default:
      return state.count;
  }
}
function UseReducerApp() {
  const [state, dispatch] = useReducer(reducer, {count: 0})
  return (
    <div className="useReducerApp">
      <h1>Hooks之useReducer</h1>
      {state.count}
      <button onClick={() => dispatch({type: 'INCREMENT'})}>+</button>
      <button onClick={() => dispatch({type: 'DECREMENT'})}>-</button>
      <button onClick={() => dispatch({type: 'UPDATE', payload: 100})}>UPDATE</button>
    </div>
  );
}
export default UseReducerApp;